﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using BEGDC.CC.BL.Common;
using BEGDC.Utility.Castle;

namespace BEGDC.CC.Web.UserControls.EV
{
	/// <summary>
	/// Summary description for AssignApp.
	/// </summary>
	public class AssignApp : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label lblStaff;
		protected System.Web.UI.WebControls.Button btnAssign;
		protected System.Web.UI.WebControls.DropDownList ddlCODStaff;
		protected System.Web.UI.HtmlControls.HtmlTableCell txtHint;
		protected System.Web.UI.WebControls.Button ibtnClose;

		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			if( !IsPostBack )
			{
				this.btnAssign.Attributes["onclick"] = "javascript:OnAssign();";
				BindCODStaff();
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.btnAssign.Click += new EventHandler(btnAssign_Click);
            this.ibtnClose.Click += new EventHandler(ibtnClose_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void BindCODStaff()
		{
			BEGDC.CC.BL.Common.IUtility utility = AppContainer.Instance[ServiceConst.UtilityService] as BEGDC.CC.BL.Common.IUtility;
			DataTable table = null;
			if( Request.QueryString["IsFilter"] == null || Request.QueryString["IsFilter"] == "true" )
			{
				table = utility.GetCODStaffByAppID(Convert.ToInt32(Request.QueryString["AppID"]), true);
			}
			else
			{
				table = utility.GetCODStaffByAppID(Convert.ToInt32(Request.QueryString["AppID"]), false);
			}

			if( table == null || table.Rows.Count == 0 )
			{
				this.txtHint.InnerHtml = "There aren't any Staffs. If you want to assign the request, please contact role admin to add one";
			}
			else
			{
				this.ddlCODStaff.DataSource = table;
				this.ddlCODStaff.DataValueField = "EmployeeNo";
				this.ddlCODStaff.DataTextField = "NameEN";
				this.ddlCODStaff.DataBind();
			}
		}

        void btnAssign_Click(object sender, EventArgs e)
		{
			Response.Write(@"<Script>returnValue='"+this.ddlCODStaff.SelectedValue+"';self.close(); </Script>");
		}

        void ibtnClose_Click(object sender, EventArgs e)
		{
			Response.Write(@"<Script>returnValue='%close%';self.close(); </Script>");
		}
	}
}
